from datetime import date
from django.http import HttpResponse

from TestModel.models import User


def saveUser(request):
    user = User(name="zhangsan", sex=True, age="28")
    user.save()
    return HttpResponse("<p>数据添加成功</p>")


def deleteUser(request):
    user = User.objects.get(id=1)
    user.delete()
    return HttpResponse("<p>删除成功</p>")


def updateUser(request):
    #User.objects.filter(id=2).update(name='李四')
    user = User.objects.get(id=2)
    #User.name = '王五'
    user.name = '王五'
    user.save()
    return HttpResponse("<p>修改成功</p>")


def findUser(request):
    #查询单个用户
    user = User.objects.get(id=3)
    #查询所有用户
    User.objects.all()
    #数据排序
    User.objects.order_by("id")
    return HttpResponse(user.name)
